package com.ceadeal.auth.service;

import com.ceadeal.auth.mapper.UserMapper;
import com.ceadeal.auth.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 功能描述: 用户服务
 *
 * 作者: Yzw
 * 日期: 2017-03-01 16:23:36
 */
@Service
@Transactional
@SuppressWarnings("Duplicates")
public class UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 功能描述: 通过用户名查找用户
     * @param
     * @return
     * @throws
     *
     * @author Yzw
     * @date 2017-03-02 11:05:14
     */
    public User findByUserName(String userName) {
        User user = null;
        Example example = new Example(User.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userName", userName);
        List<User> list = this.userMapper.selectByExample(example);
        if (list != null && list.size() > 0) {
            user = list.get(0);
        }
        return user;
    }

}
